using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace Macaw.Moss2007.ContentCopySolution
{
    class ContentCopyJobFeatureReceiver : SPFeatureReceiver
    {
        const string CONTENTCOPY_JOB_NAME = "ContentCopy";

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWebApplication webapp = properties.Feature.Parent as SPWebApplication;

            // make sure the job isn't already registered
            foreach (SPJobDefinition job in webapp.JobDefinitions)
            {
                if (job.Name == CONTENTCOPY_JOB_NAME)
                    job.Delete();
            }


            // install the job
            ContentCopyJobDefinition contentcopyJob = new ContentCopyJobDefinition(CONTENTCOPY_JOB_NAME, webapp);

            SPMinuteSchedule schedule = new SPMinuteSchedule();
            schedule.BeginSecond = 0;
            schedule.EndSecond = 59;
            schedule.Interval = 5;
            contentcopyJob.Schedule = schedule;

            contentcopyJob.Update();
        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPWebApplication webapp = properties.Feature.Parent as SPWebApplication;

            // delete the job
            foreach (SPJobDefinition job in webapp.JobDefinitions)
            {
                if (job.Name == CONTENTCOPY_JOB_NAME)
                    job.Delete();
            }

        }

        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {
            throw new Exception("The method or operation is not implemented.");
        }
    }
}
